/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.losalpes.catalogo.beans;

import com.losalpes.catalogo.entities.Promocion;
import com.losalpes.catalogo.servicios.ICatalogServiceRemote;
import javax.ejb.EJB;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author user
 */

public class PromocionBean {

    @EJB
    private ICatalogServiceRemote catalogService;

    private Promocion promocion;

    /** Creates a new instance of PromocionBean */
    public PromocionBean() {
        promocion = new Promocion();
    }

    protected CatalogBean getCatalogBean() {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpSession httpSession = (HttpSession) facesContext.getExternalContext().getSession(false);
        return (CatalogBean) httpSession.getAttribute("CatalogBean");
    }

    public Promocion getPromocion() {
        return promocion;
    }

    public void setPromocion(Promocion promocion) {
        this.promocion = promocion;
    }

    public String crearPromocion() {
        promocion.setReferencia(this.getCatalogBean().getMueble().getReferencia());
        System.out.println("referencia: " + promocion.getReferencia());
        System.out.println("fecha inicio: " + promocion.getFechaInicial().getTime());
        System.out.println("fecha fin: " + promocion.getFechaFinal().getTime());
        System.out.println("descripcion: " + promocion.getTexto());
        catalogService.addPromocion(this.getCatalogBean().getMueble(), promocion);

        return "success";
    }
}
